package com.example.xd.apt_binder;

import android.app.Activity;

import java.lang.reflect.Method;

/**
 * @auther XuDan on 2020/9/25.
 */
public class AptBinder {

    public static UnBinder bind(Activity activity) {
        try {
            Class<?> activityClass = activity.getClass();
            Class<?> viewBindingClass = Class.forName(activityClass.getName() + "_ViewBinding");
            Method bindMethod = viewBindingClass.getMethod("bind", activityClass);
            UnBinder unBinder = (UnBinder) viewBindingClass.newInstance();
            bindMethod.invoke(unBinder, activity);
            return unBinder;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
